package org.flexlancer.databases
{
	public class Alerts
	{
		private static const TABLE:String = "alerts";

		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition);
			}catch(err:Error){
				throw err;
			}
			return new Array();
		}
		
		public static function Add(parmType:String,parmDate:String,parmAction:String,parmActive:String,parmRefid:String):void{
			try{
//("alerts",["alertid INTEGER PRIMARY KEY AUTOINCREMENT","refid TEXT","alerttype TEXT", "alertdate text","alertaction TEXT","isactive INTEGER"]);

				var insert:Object = new Object();
				
				insert.alerttype = " '"+parmType+"' ";
				insert.alertaction = " '"+parmAction+"' ";
				insert.alertdate = " '"+parmDate+"' ";
				insert.refid = " '"+parmRefid+"' ";
				insert.isactive = parmActive;
				DatabaseManager.Manager.Insert(TABLE,insert);
			}catch(err:Error){
				throw err;
			}
		}
		public static function ToggleActive(parmIds:Array,status:String):void{
			try{
				var update:Object = new Object();
				update.isactive = status;
				DatabaseManager.Manager.Update(TABLE,update,"alertid IN ("+parmIds.join(",")+")");
			}catch(err:Error){
				throw err;
			}
		}
		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		}
	}
}